package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

/**
 * 游记Model
 */
@Getter
@Setter
public class Travel extends BaseDomain {
    /**
     * 草稿
     */
    public static final Integer STATE_DRAFT = 0;
    /**
     * 待审核
     */
    public static final Integer STATE_AUDIT = 1;
    /**
     * 已审核
     */
    public static final Integer STATE_RELEASE = 2;
    /**
     * 拒绝
     */
    public static final Integer STATE_REJECT = -1;

    /**
     * 标题
     */
    private String title;
    /**
     * 出行时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date travelTime;
    /**
     * 人均消费
     */
    private String perExpends;
    /**
     * 出行天数
     */
    private Integer days;
    /**
     * 同行人
     */
    private Integer person;
    /**
     * 作者
     */
    private User author;
    /**
     * 创建时间
     */
    private Date createTime;
    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
    private Date releaseTime;
    /**
     * 是否公开
     */
    private Boolean isPublic;
    /**
     * 旅行地点
     */
    private Region place;
    /**
     * 封面
     */
    private String coverUrl;
    /**
     * 最后更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd hh:mm:ss", timezone = "GMT+8")
    private Date lastUpdateTime;
    /**
     * 状态
     */
    private Integer state = STATE_DRAFT;
    /**
     * 游记内容
     */
    private TravelContent travelContent;

    /**
     * 同行人名字字符串属性
     * @return
     */
    public String getPersonName() {
        switch (person) {
            case 2:
                return "和父母";
            case 3:
                return "和朋友";
            case 4:
                return "和同事";
            case 5:
                return "和爱人";
            case 1:
                return "一个人的旅行";
            default:
                return "和其他";
        }
    }

    /**
     * 游记状态名字字符串属性
     * @return
     */
    public String getStateName() {
/*        switch (state) {
            case STATE_AUDIT:
                return "待审核";
            case STATE_RELEASE:
                return "已发布";
            case STATE_REJECT:
                return "拒绝";
            default:
                return "草稿";
        }*/
        if (STATE_AUDIT.equals(state)) {
            return "待审核";
        } else if (STATE_RELEASE.equals(state)) {
            return "已发布";
        } else if (STATE_REJECT.equals(state)) {
            return "拒绝";
        } else {
            return "草稿";
        }
    }

    public String getJson() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("coverUrl", coverUrl);
        return JSONUtil.toJSONString(map);
    }

}